#include "StdAfx.h"
#include "Effects.h"
#include <string>



ID3D10Effect *fx::WaveFX;
ID3D10Effect *fx::SkyFX;

ID3D10Effect *buildFX(ID3D10Device *device, std::wstring &filename)
{
	DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    shaderFlags |= D3D10_SHADER_DEBUG;
	shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif
 
	ID3D10Effect *fx;
	ID3D10Blob* compilationErrors = 0;
	HRESULT hr = 0;
	hr = D3DX10CreateEffectFromFile(filename.c_str(), 0, 0, 
		"fx_4_0", shaderFlags, 0, device, 0, 0, &fx, &compilationErrors, 0);
	if(FAILED(hr))
	{
		if( compilationErrors )
		{
			MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0);
			ReleaseCOM(compilationErrors);
		}
		DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true);
	} 

	return fx;
}



void fx::InitAll(ID3D10Device *device)
{
	WaveFX = buildFX(device, std::wstring(L"shading.fx") );
	SkyFX  = buildFX(device, std::wstring(L"sky.fx") );
}

void fx::DestroyAll()
{
	ReleaseCOM(WaveFX);
	ReleaseCOM(SkyFX);
}
